import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.Encoder
import org.apache.spark.sql.SparkSession
object RDDtoDF {
    case class Employee(id:Long,name: String, age: Long)
    def main(args: Array[String]) {
        val spark = SparkSession
        .builder
        .master("local[*]")
        .appName("Simple Application")
        .getOrCreate()
        import spark.implicits._
        val employeeDF = spark.sparkContext.textFile("file:///usr/local/spark/employee.txt").map(_.split(",")).map(attributes =>    Employee(attributes(0).trim.toInt,attributes(1),     attributes(2).trim.toInt)).toDF()
        employeeDF.createOrReplaceTempView("employee")
        val employeeRDD = spark.sql("select id,name,age from employee")
        employeeRDD.map(t => "id:"+t(0)+","+"name:"+t(1)+","+"age:"+t(2)).show()
    }
}
